import numpy as np
from io2excel import *

'''该模块负责文件输入参数的Excel文件读取'''


# 2.2 读取Excel文件
def readdata_xlsx():
    filename = 'template/inputdata/parameter.xlsx'
    print('读取数据中...')
    excel = loadExcel(filename)
    # 1.基本参数读取
    basic = read_sheetdata(excel, 'basic')[1][1:]
    # 2.墙体参数读取
    wall_all = read_sheetdata(excel, 'wall')
    layersName = wall_all[0][1:]
    layersLength = wall_all[1][1:]
    layersGrid = wall_all[2][1:]
    wall = [layersName, layersLength, layersGrid]
    # 3.初始条件读取
    origin_all = read_sheetdata(excel, 'origin')
    t_origin = origin_all[0][1:]
    rh_origin = origin_all[1][1:]
    origin = [t_origin, rh_origin]

    # 4 边界条件读取（分开）
    # 定义边界条件读取函数
    def loadBoundary(excel, sheetname):
        boundary_data = read_sheetdata(excel, sheetname)  # 读取excel表格数据
        boundary_value = [[]] * 6  # 设置六个空列表，用于储存边界条件的六个参数
        for i in range(6):
            # 当i=0时，数据为时间；
            # 当i=1时，数据为温度，℃；
            # 当i=2时，数据为湿度，%；
            # 当i=3时，数据为辐射，W/m2；
            # 当i=4时，数据为风速，m/s；
            # 当i=5时，数据为湿源，kg/(m2·s)；
            # 将所有解释性语言（Excel表格中的第一行数据）去掉
            boundary_value[i] = boundary_data[i][1:]

        return boundary_value

    # 4.1 外部边界条件读取
    boundary_out = loadBoundary(excel, 'boundary_out')
    # 4.2 内部边界条件读取
    boundary_in = loadBoundary(excel, 'boundary_in')

    boundary = [boundary_out, boundary_in]

    print('边界条件读取完毕！')
    return basic, wall, origin, boundary


if __name__ == '__main__':
    a = readdata_xlsx()
    print(a[3])
    print(type(a))
